
{% from 'lenta/macros.jinja' import form_field_error_list %}


{% macro view_note_href (note) -%}
    {{ url_for('lenta.view_note', namespace=note.namespace, lenta_id=note.lenta_id, note_id=note.id) }}
{%- endmacro %}


{% macro add_note_href (lenta) -%}
    {{ url_for('lenta.add_note', lenta_id=lenta.id) }}
{%- endmacro %}


{% macro edit_note_href (note) -%}
    {{ url_for('lenta.edit_note', lenta_id=note.lenta_id, note_id=note.id) }}
{%- endmacro %}


{% macro delete_note_link (note, label) -%}
    
    <a href="{{ url_for('lenta.delete_note',
                        lenta_id=note.lenta_id,
                        note_id=note.id) }}">{{ label }}</a>

{%- endmacro %}


{% macro note_form (note, errors) -%}

      <div class="form-element {{ 'error' if errors is defined and errors.title }}">
        
        <label for="title_id"></label>
        <input name="title" placeholder="Note title..." value="{{ note.title if note is defined }}" id="title_id" class="title" />
        <div id="title_error_div" class="error">
        {{ form_field_error_list (errors, 'title')|safe }}
        </div>
      </div>
      
      <div class="form-element {{ 'error' if errors is defined and errors.twit }}">
        
        <label for="twit_id"></label>
        <textarea name="twit" placeholder="Note twit..." id="twit_id" class="twit">{{note.twit if note is defined }}</textarea>
        <div class="error serverside">
        {{ form_field_error_list (errors, 'twit')|safe }}
        </div>
      </div>
      
      <div class="form-element {{ 'error' if errors is defined and errors.body }}">
        
        <label for="notetext_id"></label>
        <textarea name="body" placeholder="Note text..." id="notetext_id" class="text">{{note.body if note is defined }}</textarea>
        <div class="error serverside">
        {{ form_field_error_list (errors, 'body')|safe }}
        </div>
      </div>

	  <div id="second_form_section">
	      <div class="form-element {{ 'error' if errors is defined and errors.pubDate }}">
	        
	        <label for="pubdate_id">Publication Date</label>
	        <input name="pubDate" value="{{ note.pubDate if note is defined }}" id="pubdate_id" class="datetime" />
	        <div class="error serverside">
	        {{ form_field_error_list (errors, 'pubDate')|safe }}
	        </div>
	      </div>

	      <div class="form-element {{ 'error' if errors is defined and errors.isDraft }}">
	        
	        <label for="draft_id">Draft?</label>
	        <input type="checkbox" name="isDraft" value="{{ note.isDraft if note is defined }}" id="draft_id" class="checkbox" />
	        <div class="error serverside">
	        {{ form_field_error_list (errors, 'isDraft')|safe }}
	        </div>
	      </div>
	      
	      <div class="form-element {{ 'error' if errors is defined and errors.tags }}">
	        
	        <label for="tags_id">Tags</label>
	        <input name="tags" placeholder="Enter tags. Comma separated..." value="{{ note.tags if note is defined }}" id="tags_id" class="tags" />
	        <div class="error serverside">
	        {{ form_field_error_list (errors, 'tags') | safe }}
	        </div>
	      </div>
	   </div>   

{%- endmacro %}


{% macro note_form_js (debug) -%}

	$("#note_form").validate({
		rules: {
	    	twit: {
	       		required: true,
	       		maxlength: 140
	    	}
		},
		messages: {
	    	twit: {
	        	required: "Compose twit",
	        	maxlength: "Twit is limited to 140 symbols"
	    	}
		},
		wrapper: "div",
		errorElement: "label",
		errorClass: "error-clientside",
	{% if debug %}
		debug: true,
		submitHandler: function(form) {
	    	console.debug(form);
		},
	{% endif %}	
	});
{%- endmacro %}


{% macro notes_short_info_roll (notes) -%}

    {# Makes roll of note's short info. #}

    {% for n in notes %}
      <div class="note_short_info">
        <h3 class="note_title">
          <a href="{{ view_note_href(n) }}">{{ n.title }}</a>
        </h3>
        <div class="note_twit">{{ n.twit }}</div>
      </div>
    {% endfor %}

{%- endmacro %}


